package com.hy.mvc.web.conroller;

import com.hy.mvc.biz.service.common.support.UserContext;
import com.hy.mvc.biz.utils.CaptchaUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <pre>
 *    author  : Booker
 *    time    : 2017/12/8 17:13
 *    desc    : 输入描述
 *    version : v1.0
 * </pre>
 */
@Controller
@Api(tags = {"登录login"})
@RequestMapping("user")
public class LoginController {


    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String login(ModelMap modelMap) {
        modelMap.addAttribute("userName", "胡羽");
        return "main";
    }

    @RequestMapping(value = "/loginPage", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("登录...")
    public String loginPage(ModelMap modelMap, HttpServletResponse response) {
        return "login";
    }


    @RequestMapping(value = "/image", method = RequestMethod.GET)
    public String image(ModelMap modelMap, HttpServletResponse response) {
        try {
            CaptchaUtil captchaUtil = new CaptchaUtil();
            captchaUtil.write(response.getOutputStream());
            UserContext.current().setVCode(captchaUtil.getCode());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "main";
    }

}
